Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification age (x minutes ago) on notifcation screen #835

Closed

Conversation

clemensvonmolo
Copy link
Contributor

This PR adds "x time ago" to the bottom of the notification screen. Every notification item now stores the time at which it was received as a std::time_t (saw no reason to use std::chrono::time_point as it takes more memory with no advantages for storage). The time arrived is set in the notification manager so existing apps don't have to change anything.

I'm not really sure about the location of the text (image below) and if it would be better to use C-style string operations for memory usage and allocation optimisation.
IMG_20211117_150831
IMG_20211117_151348
..e indicator does not interfere with the message

@SteveAmor
Copy link
Contributor

Great feature.

@Itai-Nelken
Copy link
Contributor

Works nicely. Only problem is that the 'no notifications' notification has it (and it doesn't seem to update).

src/displayapp/screens/Notifications.cpp Outdated Show resolved Hide resolved
src/displayapp/screens/Notifications.cpp Outdated Show resolved Hide resolved
@Tiggilyboo
Copy link

Not sure if this is still active, but this would be great to get merged. What is left to do / blocking this from getting in?

@clemensvonmolo
Copy link
Contributor Author

The problem seems to have been me forgetting about it. Now I think this has to be adjusted to newer changes that happened in the meantime. I don't have time today but I can try doing that tomorrow.

@devnoname120
Copy link

The problem seems to have been me forgetting about it. Now I think this has to be adjusted to newer changes that happened in the meantime. I don't have time today but I can try doing that tomorrow.

Friendly bump 🙏

@JF002
Copy link
Collaborator

JF002 commented Jun 19, 2022

@clemensvonmolo @devnoname120 Sorry for not providing any feedback about this PR for so long. Is there any reason for it to be still a draft?

@clemensvonmolo
Copy link
Contributor Author

I can set it to a normal PR for now, but Github says there will be conflicts and I can't do anything about that in the next three days while I'm on a class trip. It might also be a good idea to discuss the positioning of the text again. Anyway thanks for the positive feedback and patience everyone!

@clemensvonmolo clemensvonmolo marked this pull request as ready for review June 19, 2022 19:54
@clemensvonmolo
Copy link
Contributor Author

Okay this should work now. I've also created InfiniTimeOrg/InfiniSim#46 to fix the build issue it is currently facing with this PR.

@clemensvonmolo clemensvonmolo requested a review from Riksu9000 July 28, 2022 17:58
@Riksu9000 Riksu9000 added this to the 1.11.0 milestone Jul 30, 2022
Copy link
Contributor

@Riksu9000 Riksu9000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow up PR there could be special messages like "Just now" or "Yesterday".

} else {
timeUnit = 'm';
}
lv_obj_t* alert_age = lv_label_create(container, nullptr);
Copy link
Contributor

@Riksu9000 Riksu9000 Jul 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables names should be like this. Don't commit this suggestion.

Suggested change
lv_obj_t* alert_age = lv_label_create(container, nullptr);
lv_obj_t* alertAge = lv_label_create(container, nullptr);

lv_obj_t* alert_age = lv_label_create(container, nullptr);
lv_label_set_text_fmt(alert_age, "%d%c ago", ageInt, timeUnit);
// same format as alert_count
lv_obj_align(alert_age, container, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -16);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the padding similar to the text.

Suggested change
lv_obj_align(alert_age, container, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -16);
lv_obj_align(alert_age, container, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -10);

Comment on lines +293 to +296
if ((ageInt / (60 * 24)) >= 1) {
ageInt /= (60 * 24);
timeUnit = 'd';
} else if ((ageInt / 60) >= 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be simplified.

Suggested change
if ((ageInt / (60 * 24)) >= 1) {
ageInt /= (60 * 24);
timeUnit = 'd';
} else if ((ageInt / 60) >= 1) {
if (ageInt >= 60 * 24) {
ageInt /= (60 * 24);
timeUnit = 'd';
} else if (ageInt >= 60) {

@@ -57,6 +62,7 @@ namespace Pinetime {
size_t NbNotifications() const;

private:
Controllers::DateTime& dateTimeController;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can even store a const reference, to make it explicit, that a notification can't change the date-time, just get the current date and time

Suggested change
Controllers::DateTime& dateTimeController;
const Controllers::DateTime& dateTimeController;

std::array<char, MessageSize + 1> message;
Categories category = Categories::Unknown;

const char* Message() const;
const char* Title() const;
};

NotificationManager(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can even store a const reference, to make it explicit, that a notification can't change the date-time, just get the current date and time

Suggested change
NotificationManager(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
NotificationManager(const Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At present it is not possible since DateTime controller updates it member variables during time retrieving.

std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds> DateTime::CurrentDateTime() {
xSemaphoreTake(mutex, portMAX_DELAY);
UpdateTime(nrf_rtc_counter_get(portNRF_RTC_REG), false);
xSemaphoreGive(mutex);
return currentDateTime;
}
void DateTime::UpdateTime(uint32_t systickCounter, bool forceUpdate) {
// Handle systick counter overflow
uint32_t systickDelta = 0;
if (systickCounter < previousSystickCounter) {
systickDelta = static_cast<uint32_t>(portNRF_RTC_MAXTICKS) - previousSystickCounter;
systickDelta += systickCounter + 1;
} else {
systickDelta = systickCounter - previousSystickCounter;
}
auto correctedDelta = systickDelta / configTICK_RATE_HZ;
// If a second hasn't passed, there is nothing to do
// If the time has been changed, set forceUpdate to trigger internal state updates
if (correctedDelta == 0 && !forceUpdate) {
return;
}
auto rest = systickDelta % configTICK_RATE_HZ;
if (systickCounter >= rest) {
previousSystickCounter = systickCounter - rest;
} else {
previousSystickCounter = static_cast<uint32_t>(portNRF_RTC_MAXTICKS) - (rest - systickCounter - 1);
}
currentDateTime += std::chrono::seconds(correctedDelta);

It can be overcomed with mutable but I am not sure whether this is a good idea.

@NeroBurner NeroBurner modified the milestones: 1.11.0, 1.12.0 Oct 16, 2022
@JF002 JF002 removed this from the 1.12.0 milestone Jan 5, 2023
@yusufmte
Copy link
Contributor

Any plans to rebase/eventually merge this sometime? Seems it would be a nice improvement.

@LinuxinaBit
Copy link

This would go very well with #1697 if the grey notification box was made slightly smaller vertically to allow a small bottom bar for this and the notification icons.

@Boteium
Copy link

Boteium commented Jul 21, 2023

lv_obj_t* alert_age should be the last object to be created. Otherwise, objects such as alert_caller will be on top of it and cause the alert_age to be invisible in IncomingCall message.

This also needs a rebase.

@vchigrin
Copy link

vchigrin commented Dec 8, 2024

Yet another friendly bump :)

@mark9064
Copy link
Member

mark9064 commented Dec 8, 2024

It looks like the original author is not working on this anymore, so if anyone would like to rebase this + apply the feedback onto a new PR you'd be totally welcome to do that

@vchigrin
Copy link

Rebased on the latest main branch in PR #2198 .
@clemensvonmolo - if you prefer continue work on your own - I can step back. I am interested only in final result.

@clemensvonmolo
Copy link
Contributor Author

Rebased on the latest main branch in PR #2198 . @clemensvonmolo - if you prefer continue work on your own - I can step back. I am interested only in final result.

Feel free to continue. I wouldn't have had time until after Christmas anyways and on top of that I'm not currently up to date with the codebase of InfiniTime which would only mean more work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.